package com.dotstone.chipism.activity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.dotstone.chipism.R;
import com.dotstone.chipism.adapter.KeySelectAdapter;
import com.dotstone.chipism.bean.DeviceType;
import com.dotstone.chipism.bean.Key;
import com.dotstone.chipism.bean.KeyCmd;
import com.dotstone.chipism.bean.MySocket;
import com.dotstone.chipism.bean.MySocket.DisconnectListener;
import com.dotstone.chipism.bean.MySocket.RecDataCallBackListener_Study;
import com.dotstone.chipism.util.ConvertUtil;
import com.dotstone.chipism.util.DeviceManager;
import com.dotstone.chipism.util.KeyManager;
import com.dotstone.chipism.util.SocketManager;
import com.dotstone.chipism.util.ToastShow;
import com.dotstone.chipism.util.Util;
import com.dotstone.chipism.view.slidingfragmenu.BarUtils;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class DIYAirRemoteActivity extends BaseActivity {

	private LinearLayout mBackL;
	private TextView mStatusBar;
	private TextView mTitleTv;
	private Button mFinishB;
	private Button mEnsureB;
	private ImageView mTypeImg;
	private TextView mTypeTv;
	private Dialog dialog;
	private Dialog dialog1;
	private Dialog dialog2;
	private Dialog dialog3;
	private Dialog dialog4;
	private Dialog dialog5;
	private Dialog dialog6;
	private Dialog dialog7;
	private TextView mProgressTv;
	private Button mCancelB1;
	private Button mCancelB2;
	private Button mCancelB3;
	private Button mEnsureB1;
	private Button mEnsureB2;
	private Button mCancelB4;
	private Button mEnsureB4;
	private Button mCancelB5;
	private Button mEnsureB5;
	private Button mJiaB;
	private Button mJianB;
	private TextView mTempTv;
	private Button mModeB;
	private Button quxiao;
	private Button queding;
	private RadioGroup mModeGroup;
	private Button quxiao1;
	private Button queding1;
	private RadioGroup mWindGroup;
	private Button quxiao2;
	private Button queding2;
	private int tempValue = 22;
	private String temp;
	private String mode;
	private TextView mKeyCountTv;
	private LinearLayout mTestL;
	private ExpandableListView mPairedKeyL; // 已完成配置的按键列表
	private ListView mSelectKeyL; // 供用户选择所需配置的按键列表
	private List<Key> mPairedKeys = new ArrayList<Key>();
	private List<Key> mSelectKeys = new ArrayList<Key>();
	private MySocket socket;
	private boolean intercepting;
	// private
	private int num;
	private int count = 0;
	private String cmd;
	private String code;
	private String ir_data;
	private int type;
	private int time;
	private KeyPairExpandAdapter mPairAdapter;
	private KeySelectAdapter mSelectAdapter;
	private Key mSelectedkey;
	public static DIYAirRemoteActivity diyAirRemoteActivity;
	private int tempPointer = 0;
	private int modelPointer = 0;
	private int windPointer = 0;
	// private boolean isRu

	// private HashMap<Integer, String> irDataMaps = new HashMap<Integer,
	// String>();
	@Override
	public void widgetClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back_layout:
			finish();
			break;
		case R.id.finish_btn:
			// 判断是否已经学习了按键
			// 如果没有 则提示尚未配置 无法保存
			// 如果有 则保存按键至keyManager
			// 跳转至保存界面
			if (mPairedKeys.size() == 0) {
				ToastShow.Show(getApplicationContext(), "尚未配置按键");
			} else {
				List<Key> keys = mPairAdapter.getData();
				KeyManager.getInstance().setDIYKeyList(keys);
				// KeyManager.getInstance().setDIYKeyList(mPairedKeys);
				Intent intent = new Intent(DIYAirRemoteActivity.this, DIYAirRemoteActivity1.class);
				intent.putExtra("type", DeviceType.DEVICE_TYPE_AIR_CONTROLLER);
				startActivity(intent);
			}
			break;
		case R.id.ensure_btn:
			// 开始配置
			// 弹出正在侦听弹出框
			// 开启线程改变句号 同时做超时判断
			startInterception();
			break;
		case R.id.cancel_btn1:
			// 取消弹出框
			// 取消监听
			dialog.dismiss();
			break;
		case R.id.cancel_btn2:
			dialog1.dismiss();
			break;
		case R.id.ensure_btn1:
			dialog1.dismiss();
			showKeyPairDialog();
			break;
		case R.id.cancel_btn3:
			dialog2.dismiss();
			break;
		case R.id.ensure_btn2:
			startInterception();
			break;
		case R.id.cancel_btn4:
			dialog3.dismiss();
			break;
		case R.id.ensure_btn4:
			boolean e = false;
			for (int i = 0; i < mPairedKeys.size(); i++) {
				if (mPairedKeys.get(i).getKeyNum() == mSelectedkey.getKeyNum()) {
					e = true;
				}
			}
			if (e) {
				ToastShow.Show(getApplicationContext(), "该按键已配置");
				return;
			} else {
				dialog3.dismiss();
				showPairFinish();
			}
			break;
		case R.id.cancel_btn5:
			dialog4.dismiss();
			if (mSelectedkey.getKeyNum() == 811 || mSelectedkey.getKeyNum() == 812 && mSelectedkey.getKeyNum() == 832
					&& mSelectedkey.getKeyNum() == 833) {
				return;
			}
			mSelectedkey.setCodeValue(ir_data);
			mPairedKeys.add(mSelectedkey);
			mPairAdapter.notifyDataSetChanged();
			if (mPairedKeys.size() > 0) {
				mEnsureB.setText("DIY下一键");
			} else {
				mEnsureB.setText("开始DIY");
			}
			break;
		case R.id.ensure_btn5:
			dialog4.dismiss();
			if (mSelectedkey.getKeyNum() == 811 || mSelectedkey.getKeyNum() == 812 || mSelectedkey.getKeyNum() == 832
					|| mSelectedkey.getKeyNum() == 833) {
				return;
			}
			mSelectedkey.setCodeValue(ir_data);
			mPairedKeys.add(mSelectedkey);
			mPairAdapter.notifyDataSetChanged();
			if (mPairedKeys.size() > 0) {
				mEnsureB.setText("DIY下一键");
			} else {
				mEnsureB.setText("开始DIY");
			}
			break;
		case R.id.test_l:
			String cmd = ConvertUtil.getInstance().convertInfraredCmd(ir_data);
			socket.sendMqttData(cmd);
			break;
		case R.id.quxiao:
			dialog5.dismiss();
			break;
		case R.id.queding:
			temp = mTempTv.getText().toString();
			tempValue = Integer.parseInt(temp);
			tempPointer = tempValue;
			mode = mModeB.getText().toString();
			Log.i("wmy", "tempValue = " + tempValue + " mode = " + mode);
			getTempKeyCmd(tempValue);
			dialog3.dismiss();
			dialog5.dismiss();
			// showPairFinish();
			break;
		case R.id.quxiao1:
			dialog6.dismiss();
			break;
		case R.id.queding1:
			getModelKeyCmd(num);
			dialog3.dismiss();
			dialog6.dismiss();
			// showPairFinish();
			// }
			break;
		case R.id.quxiao2:
			dialog7.dismiss();
			break;
		case R.id.queding2:
			getWindKeyCmd(num);
			dialog3.dismiss();
			dialog7.dismiss();
			// showPairFinish();

			break;
		case R.id.jia:
			tempValue++;
			mTempTv.setText(tempValue + "");
			break;
		case R.id.jian:
			tempValue--;
			mTempTv.setText(tempValue + "");
			break;
		default:
			break;
		}
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	private void getWindKeyCmd(int num) {
		windPointer = num;
		KeyCmd keyCmd = new KeyCmd(type, num, ir_data);
		boolean e = false;
		Key k = new Key("风量", 1, 833, false);
		for (int i = 0; i < mPairedKeys.size(); i++) {
			if (mPairedKeys.get(i).getKeyNum() == mSelectedkey.getKeyNum()) {
				List<KeyCmd> keyCmds = mPairedKeys.get(i).getCmds();
				keyCmds.add(keyCmd);
				Collections.sort(keyCmds, numComparator);
				mPairedKeys.get(i).setCmds(keyCmds);
				e = true;
			}
		}
		if (!e) {
			mSelectedkey.getCmds().add(keyCmd);
			mPairedKeys.add(mSelectedkey);
			// k.getCmds().add(keyCmd);
			// mPairedKeys.add(k);
		}
		mPairAdapter.notifyDataSetChanged();
		if (mPairedKeys.size() > 0) {
			mEnsureB.setText("DIY下一键");
		} else {
			mEnsureB.setText("开始DIY");
		}
	}

	private void getModelKeyCmd(int num) {
		modelPointer = num;
		KeyCmd keyCmd = new KeyCmd(type, num, ir_data);
		boolean e = false;
		Key k = new Key("模式", 1, 832, false);
		for (int i = 0; i < mPairedKeys.size(); i++) {
			if (mPairedKeys.get(i).getKeyNum() == mSelectedkey.getKeyNum()) {
				List<KeyCmd> keyCmds = mPairedKeys.get(i).getCmds();
				keyCmds.add(keyCmd);
				Collections.sort(keyCmds, numComparator);
				// mPairedKeys.get(i).getCmds().add(keyCmd);
				mPairedKeys.get(i).setCmds(keyCmds);
				e = true;
			}
		}
		if (!e) {
			mSelectedkey.getCmds().add(keyCmd);
			mPairedKeys.add(mSelectedkey);
			// k.getCmds().add(keyCmd);
			// mPairedKeys.add(k);
			// for (int i = 0; i < mPairedKeys.size(); i++) {
			// Log.e("wmy", "mPairedKeys" + i + " "
			// +
			// KeyManager.getInstance().getKeyNameById(mPairedKeys.get(i).getKeyNum()));
			// }
		}
		mPairAdapter.notifyDataSetChanged();
		if (mPairedKeys.size() > 0) {
			mEnsureB.setText("DIY下一键");
		} else {
			mEnsureB.setText("开始DIY");
		}
	}

	private void getTempKeyCmd(int num) {
		KeyCmd keyCmd = new KeyCmd(type, num, ir_data);
		boolean e = false;
		Key key2 = new Key();
		if (mSelectedkey.getKeyNum() == 811) {
			key2 = new Key("温度-", 1, 812, false);
		} else if (mSelectedkey.getKeyNum() == 812) {
			key2 = new Key("温度+", 1, 811, false);
		}
		for (int i = 0; i < mPairedKeys.size(); i++) {
			if (mPairedKeys.get(i).getKeyNum() == mSelectedkey.getKeyNum()) {
				List<KeyCmd> keyCmds = mPairedKeys.get(i).getCmds();
				keyCmds.add(keyCmd);
				Collections.sort(keyCmds, numComparator);
				mPairedKeys.get(i).setCmds(keyCmds);
				e = true;
			}
			if (mPairedKeys.get(i).getKeyNum() == key2.getKeyNum()) {
				List<KeyCmd> keyCmds = mPairedKeys.get(i).getCmds();
				keyCmds.add(keyCmd);
				Collections.sort(keyCmds, numComparator);
				mPairedKeys.get(i).setCmds(keyCmds);
				e = true;
			}
		}
		if (!e) {
			mSelectedkey.getCmds().add(keyCmd);
			mPairedKeys.add(mSelectedkey);
			key2.getCmds().add(keyCmd);
			mPairedKeys.add(key2);
			Log.i("wmy", "添加一个新按键 mPairedKeys.size() = " + mPairedKeys.size());
		}
		mPairAdapter.notifyDataSetChanged();
		if (mPairedKeys.size() > 0) {
			mEnsureB.setText("DIY下一键");
		} else {
			mEnsureB.setText("开始DIY");
		}
	}

	public static Comparator numComparator = new Comparator() {
		@Override
		public int compare(Object o1, Object o2) {
			return (((KeyCmd) o1).getNum() < ((KeyCmd) o2).getNum() ? -1
					: (((KeyCmd) o1).getNum() == ((KeyCmd) o2).getNum() ? 0 : 1));
		}
	};

	Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 0:
				// 计时用
				num = msg.arg1 % 3;
				switch (num) {
				case 0:
					mProgressTv.setText(getString(R.string.interception1));
					break;
				case 1:
					mProgressTv.setText(getString(R.string.interception2));
					break;
				case 2:
					mProgressTv.setText(getString(R.string.interception3));
					break;
				default:
					break;
				}
				break;
			case 1:
				// 超时 取消侦听
				// 弹出超时dialog
				intercepting = false;
				dialog.dismiss();
				showTimeout();
				break;
			case 2:
				// 侦听成功
				// 侦听成功的dialog消失
				// 显示
				intercepting = false;
				dialog.dismiss();
				showReceived();
				break;
			case 3:
				int groupPosition = msg.arg1;
				int childPosition = msg.arg2;
				if (mPairedKeys.get(groupPosition).getKeyNum() == 832) {
					mPairedKeys.get(groupPosition).getCmds().remove(childPosition);
					if (mPairedKeys.get(groupPosition).getCmds().size() == 0) {
						mPairedKeys.remove(groupPosition);
					}
				} else if (mPairedKeys.get(groupPosition).getKeyNum() == 832) {
					if (mPairedKeys.get(groupPosition).getCmds().size() == 0) {
						mPairedKeys.remove(groupPosition);
					}
				} else if (mPairedKeys.get(groupPosition).getKeyNum() == 812) {
					mPairedKeys.get(groupPosition).getCmds().remove(childPosition);
					for (int i = 0; i < mPairedKeys.size(); i++) {
						if (mPairedKeys.get(i).getKeyNum() == 811) {
							mPairedKeys.get(i).getCmds().remove(childPosition);
						}
					}
					if (mPairedKeys.get(groupPosition).getCmds().size() == 0) {
						mPairedKeys.remove(groupPosition);
						for (int i = 0; i < mPairedKeys.size(); i++) {
							if (mPairedKeys.get(i).getKeyNum() == 811) {
								mPairedKeys.remove(i);
							}
						}
					}
				} else if (mPairedKeys.get(groupPosition).getKeyNum() == 811) {
					mPairedKeys.get(groupPosition).getCmds().remove(childPosition);
					for (int i = 0; i < mPairedKeys.size(); i++) {
						if (mPairedKeys.get(i).getKeyNum() == 812) {
							mPairedKeys.get(i).getCmds().remove(childPosition);
						}
					}

					if (mPairedKeys.get(groupPosition).getCmds().size() == 0) {
						mPairedKeys.remove(groupPosition);
						for (int i = 0; i < mPairedKeys.size(); i++) {
							if (mPairedKeys.get(i).getKeyNum() == 812) {
								mPairedKeys.remove(i);
							}
						}
					}
				}
				if (mPairedKeys.size() > 0) {
					mEnsureB.setText("DIY下一键");
				} else {
					mEnsureB.setText("开始DIY");
				}
				mPairAdapter.notifyDataSetChanged();
				break;
			default:
				break;
			}
		}
	};

	private void startInterception() {
		checkTimeOut();
		dialog.setContentView(R.layout.dialog_interception);
		Window dialogWindow = dialog.getWindow();
		mProgressTv = (TextView) dialog.findViewById(R.id.interception_tv);
		mCancelB1 = (Button) dialog.findViewById(R.id.cancel_btn1);
		mCancelB1.setOnClickListener(this);
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		dialogWindow.setGravity(Gravity.CENTER);
		lp.width = LayoutParams.FILL_PARENT;
		dialogWindow.setAttributes(lp);
		Log.e("wmy", "发送学习命令 ");
		cmd = ConvertUtil.getInstance().convertStudyCmd();
		if (socket.isLocalSuccess()) {
			socket.sendMqttData(cmd);
			if (Util.isRunningForeground(DIYAirRemoteActivity.this)) {
				dialog.show();
			}
		} else {
			ToastShow.Show(getApplicationContext(), "网关连接已断开，请稍后重试");
		}
	}

	private void showTimeout() {
		dialog2.setContentView(R.layout.dialog_interception_timeout);
		Window dialogWindow = dialog2.getWindow();
		mCancelB3 = (Button) dialog2.findViewById(R.id.cancel_btn3);
		mCancelB3.setOnClickListener(this);
		mEnsureB2 = (Button) dialog2.findViewById(R.id.ensure_btn2);
		mEnsureB2.setOnClickListener(this);
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		dialogWindow.setGravity(Gravity.CENTER);
		lp.width = LayoutParams.FILL_PARENT;
		dialogWindow.setAttributes(lp);
		if (Util.isRunningForeground(DIYAirRemoteActivity.this)) {
			dialog2.show();
		}
	}

	private void showReceived() {
		dialog1.setContentView(R.layout.dialog_received);
		Window dialogWindow = dialog1.getWindow();
		mCancelB2 = (Button) dialog1.findViewById(R.id.cancel_btn2);
		mCancelB2.setOnClickListener(this);
		mEnsureB1 = (Button) dialog1.findViewById(R.id.ensure_btn1);
		mEnsureB1.setOnClickListener(this);
		mTestL = (LinearLayout) dialog1.findViewById(R.id.test_l);
		mTestL.setOnClickListener(this);
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		dialogWindow.setGravity(Gravity.CENTER);
		lp.width = LayoutParams.FILL_PARENT;
		dialogWindow.setAttributes(lp);
		if (Util.isRunningForeground(DIYAirRemoteActivity.this)) {
			dialog1.show();
		}
	}

	private void showKeyPairDialog() {
		dialog3.setContentView(R.layout.dialog_pair_key);
		Window dialogWindow = dialog3.getWindow();
		mCancelB4 = (Button) dialog3.findViewById(R.id.cancel_btn4);
		mCancelB4.setOnClickListener(this);
		mEnsureB4 = (Button) dialog3.findViewById(R.id.ensure_btn4);
		mEnsureB4.setOnClickListener(this);
		mSelectKeyL = (ListView) dialog3.findViewById(R.id.key_lv1);
		initSelectionKey();
		mSelectAdapter = new KeySelectAdapter(getApplicationContext(), mSelectKeys);
		mSelectKeyL.setAdapter(mSelectAdapter);
		mSelectKeyL.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View v, int p, long arg3) {
				// TODO Auto-generated method stub
				for (int i = 0; i < mSelectKeys.size(); i++) {
					mSelectKeys.get(i).setIsSelected(false);
				}
				mSelectKeys.get(p).setIsSelected(true);
				mSelectedkey = mSelectKeys.get(p);
				mSelectAdapter.notifyDataSetChanged();
				if (mSelectKeys.get(p).getKeyNum() == 811 || mSelectKeys.get(p).getKeyNum() == 812) {
					tempSelectionDialog();
				}
				if (mSelectKeys.get(p).getKeyNum() == 832) {
					modeSelectionDialog();
				}
				if (mSelectKeys.get(p).getKeyNum() == 833) {
					windSelectionDialog();
				}
			}
		});
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		dialogWindow.setGravity(Gravity.CENTER);
		lp.width = LayoutParams.FILL_PARENT;
		dialogWindow.setAttributes(lp);
		if (Util.isRunningForeground(DIYAirRemoteActivity.this)) {
			dialog3.show();
		}
	}

	private void showPairFinish() {
		dialog4.setContentView(R.layout.dialog_finish_paired);
		Window dialogWindow = dialog4.getWindow();
		mCancelB5 = (Button) dialog4.findViewById(R.id.cancel_btn5);
		mCancelB5.setOnClickListener(this);
		mEnsureB5 = (Button) dialog4.findViewById(R.id.ensure_btn5);
		mEnsureB5.setOnClickListener(this);
		mKeyCountTv = (TextView) dialog4.findViewById(R.id.finish_tv);
		mKeyCountTv.setText("完成" + (mPairedKeys.size() + 1) + "组按键信号的接收");
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		dialogWindow.setGravity(Gravity.CENTER);
		lp.width = LayoutParams.FILL_PARENT;
		dialogWindow.setAttributes(lp);
		if (Util.isRunningForeground(DIYAirRemoteActivity.this)) {
			dialog4.show();
		}
	}

	private void tempSelectionDialog() {
		type = 4;
		dialog5.setContentView(R.layout.dialog_temp_selection);
		Window dialogWindow = dialog5.getWindow();
		mJiaB = (Button) dialog5.findViewById(R.id.jia);
		mJianB = (Button) dialog5.findViewById(R.id.jian);
		mTempTv = (TextView) dialog5.findViewById(R.id.temp);
		mTempTv.setText(tempValue + "");
		mModeB = (Button) dialog5.findViewById(R.id.mode_btn1);
		quxiao = (Button) dialog5.findViewById(R.id.quxiao);
		queding = (Button) dialog5.findViewById(R.id.queding);
		mJiaB.setOnClickListener(this);
		mJianB.setOnClickListener(this);
		// mModeB.setOnClickListener(this);
		quxiao.setOnClickListener(this);
		queding.setOnClickListener(this);
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		dialogWindow.setGravity(Gravity.CENTER);
		lp.width = LayoutParams.FILL_PARENT;
		dialogWindow.setAttributes(lp);
		if (Util.isRunningForeground(DIYAirRemoteActivity.this)) {
			dialog5.show();
		}
	}

	private void modeSelectionDialog() {
		type = 1;
		dialog6.setContentView(R.layout.dialog_mode_selection);
		Window dialogWindow = dialog6.getWindow();
		mModeGroup = (RadioGroup) dialog6.findViewById(R.id.mode_group);
		quxiao1 = (Button) dialog6.findViewById(R.id.quxiao1);
		queding1 = (Button) dialog6.findViewById(R.id.queding1);
		quxiao1.setOnClickListener(this);
		queding1.setOnClickListener(this);
		mModeGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				// TODO Auto-generated method stub
				Log.i("wmy", "所选的Button变了" + group.getCheckedRadioButtonId() + " " + checkedId);
				String mode = ((Button) dialog6.findViewById(checkedId)).getText().toString();
				int tag = Integer.parseInt(((Button) dialog6.findViewById(checkedId)).getTag().toString());
				Log.i("wmy", "选择了" + mode);
				switch (tag) {
				case 1:
					num = 1;
					break;
				case 2:
					num = 2;
					break;
				case 3:
					num = 3;
					break;
				case 4:
					num = 4;
					break;
				case 5:
					num = 5;
					break;
				default:
					break;
				}
			}
		});
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		dialogWindow.setGravity(Gravity.CENTER);
		lp.width = LayoutParams.FILL_PARENT;
		dialogWindow.setAttributes(lp);
		if (Util.isRunningForeground(DIYAirRemoteActivity.this)) {
			dialog6.show();
		}
	}

	private void windSelectionDialog() {
		type = 2;
		dialog7.setContentView(R.layout.dialog_wind_selection);
		Window dialogWindow = dialog7.getWindow();
		mWindGroup = (RadioGroup) dialog7.findViewById(R.id.wind_group);
		quxiao2 = (Button) dialog7.findViewById(R.id.quxiao2);
		queding2 = (Button) dialog7.findViewById(R.id.queding2);
		quxiao2.setOnClickListener(this);
		queding2.setOnClickListener(this);
		mWindGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				// TODO Auto-generated method stub
				Log.i("wmy", "所选的Button变了" + group.getCheckedRadioButtonId() + " " + checkedId);
				String wind = ((Button) dialog7.findViewById(checkedId)).getText().toString();
				Log.i("wmy", "选择了" + wind);
				int tag = Integer.parseInt(((Button) dialog7.findViewById(checkedId)).getTag().toString());
				switch (tag) {
				case 1:
					num = 1;
					break;
				case 2:
					num = 2;
					break;
				case 3:
					num = 3;
					break;
				case 4:
					num = 4;
					break;
				case 5:
					num = 5;
					break;
				default:
					break;
				}
			}
		});
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		dialogWindow.setGravity(Gravity.CENTER);
		lp.width = LayoutParams.FILL_PARENT;
		dialogWindow.setAttributes(lp);
		if (Util.isRunningForeground(DIYAirRemoteActivity.this)) {
			dialog7.show();
		}
	}

	@Override
	public void initParms(Bundle parms) {
		// TODO Auto-generated method stub

	}

	@Override
	public View bindView() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int bindLayout() {
		// TODO Auto-generated method stub
		return R.layout.activity_diy_air;
	}

	@Override
	public void initView(View view) {
		// TODO Auto-generated method stub
		Log.i("wmy", getClass().getSimpleName());
		mBackL = $(R.id.back_layout);
		mStatusBar = $(R.id.tv_statusBar_mian);
		mTitleTv = $(R.id.title_tv);
		mTitleTv.setText("DIY您的遥控器");
		mTypeImg = $(R.id.mode_icon_img);
		mTypeTv = $(R.id.mould_tv);
		mFinishB = $(R.id.finish_btn);
		mEnsureB = $(R.id.ensure_btn);
		mPairedKeyL = $(R.id.key_lv);
		mPairedKeyL.setGroupIndicator(null);
		diyAirRemoteActivity = this;
		// type = getIntent().getIntExtra("type", 999);
		setTitle();
		dialog = new Dialog(DIYAirRemoteActivity.this, R.style.MyDialogStyle);
		dialog1 = new Dialog(DIYAirRemoteActivity.this, R.style.MyDialogStyle);
		dialog2 = new Dialog(DIYAirRemoteActivity.this, R.style.MyDialogStyle);
		dialog3 = new Dialog(DIYAirRemoteActivity.this, R.style.MyDialogStyle);
		dialog4 = new Dialog(DIYAirRemoteActivity.this, R.style.MyDialogStyle);
		dialog5 = new Dialog(DIYAirRemoteActivity.this, R.style.MyDialogStyle);
		dialog6 = new Dialog(DIYAirRemoteActivity.this, R.style.MyDialogStyle);
		dialog7 = new Dialog(DIYAirRemoteActivity.this, R.style.MyDialogStyle);
		// mPairAdapter = new KeyPairExpandAdapter(getApplicationContext(),
		// deletel, testl);
		mPairAdapter = new KeyPairExpandAdapter();
		// mPairAdapter.setData(mPairedKeys);
		mPairedKeyL.setAdapter(mPairAdapter);
		boolVersion();
		mBackL.setOnClickListener(this);
		mFinishB.setOnClickListener(this);
		mEnsureB.setOnClickListener(this);
		dialog.setOnCancelListener(new OnCancelListener() {

			@Override
			public void onCancel(DialogInterface arg0) {
				// TODO Auto-generated method stub
				Log.i("wmy", "取消dialog");
			}
		});
		dialog1.setOnCancelListener(new OnCancelListener() {

			@Override
			public void onCancel(DialogInterface arg0) {
				// TODO Auto-generated method stub
				Log.i("wmy", "取消dialog1");
			}
		});
		dialog2.setOnCancelListener(new OnCancelListener() {

			@Override
			public void onCancel(DialogInterface arg0) {
				// TODO Auto-generated method stub
				Log.i("wmy", "取消dialog2");
			}
		});
		socket = SocketManager.getInstance().sMap.get(DeviceManager.getInstance().getmWlanId());
		setRecall();
		mPairedKeyL.setOnScrollListener(new OnScrollListener() {

			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				// TODO Auto-generated method stub
				mPairedKeyL.requestFocus();
				mPairedKeyL.setFocusable(true);
				mPairedKeyL.setFocusableInTouchMode(true);
			}

			@Override
			public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

			}
		});
		mPairedKeyL.setOnGroupClickListener(new OnGroupClickListener() {

			@Override
			public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
				// TODO Auto-generated method stub
				Log.i("wmy", "点击了" + mPairedKeys.get(groupPosition).getKeyNum());
				return true;
			}
		});
		mPairedKeyL.setOnGroupExpandListener(new OnGroupExpandListener() {

			@Override
			public void onGroupExpand(int groupPosition) {
				// TODO Auto-generated method stub
				for (int i = 0; i < mPairedKeyL.getExpandableListAdapter().getGroupCount(); i++) {
					if (groupPosition != i) {// 关闭其他分组
						mPairedKeyL.collapseGroup(i);
					}
				}
			}
		});
	}

	private void setTitle() {
		mTypeImg.setImageResource(R.drawable.machine_air_tag);
		mTypeTv.setText(getString(R.string.yaokong_add_kongtiao) + "模版");
	}

	private void initSelectionKey() {
		mSelectKeys = KeyManager.getInstance().getAirCondKey();
		Log.i("wmy", DeviceType.DEVICE_TYPE_AIR_CONTROLLER + " mSelectKeys = " + mSelectKeys.size());
	}

	@Override
	public void setListener() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doBusiness(Context mContext) {
		// TODO Auto-generated method stub

	}

	public void boolVersion() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

			Window window = getWindow();
			window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
					WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
			// 透明导航栏
			// getWindow().addFlags(
			// WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
			// 改变titlebar的高度
			int statusbarHeight = BarUtils.getStatusBarHeight(this);
			RelativeLayout.LayoutParams layoutParams1 = (RelativeLayout.LayoutParams) mStatusBar.getLayoutParams();
			layoutParams1.height = statusbarHeight;
			mStatusBar.setLayoutParams(layoutParams1);
			mStatusBar.setVisibility(View.VISIBLE);
		} else {
			mStatusBar.setVisibility(View.GONE);
		}
	}

	private void checkTimeOut() {
		time = 0;
		intercepting = true;
		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				while (intercepting) {
					try {
						Message msg = Message.obtain();
						if (time < 15) {
							msg.what = 0;
							msg.arg1 = time;
						} else {
							msg.what = 1;
						}
						mHandler.sendMessage(msg);
						Thread.sleep(1000);
						time++;
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

				}
			}
		}).start();
	}

	private void setRecall() {
		socket.setRecDataCallBackListener_Study(new RecDataCallBackListener_Study() {

			@Override
			public void onReceiveData(String recData) {
				parseRecData(recData);
			}
		});
		socket.setOnDisconnectListener(new DisconnectListener() {

			@Override
			public void onDisconnect() {
				// TODO Auto-generated method stub
				Log.i("wmy", "在DIY的时候断开0.0");
				Message message = Message.obtain();
				message.what = 1;
				mHandler.sendMessage(message);
			}
		});
	}

	private void parseRecData(String recData) {
		try {
			Log.i("wmy", "解析数据 = " + recData);
			JSONObject jo = new JSONObject(recData);
			String g = jo.getString("g");
			JSONObject jo1 = new JSONObject(g);
			code = jo1.optInt("code") + "";
			// Log.i("wmy", "code = " + code);
			Message msg = Message.obtain();
			if (code.equals("0")) {
				// 继续解析
				ir_data = jo1.getString("ir_data");
				Log.i("wmy", "解析得到 ir_data = " + ir_data);
				msg.what = 2;
			} else if (code.equals("2")) {
				msg.what = 1;
				Log.i("wmy", "操作超时");
			}
			mHandler.sendMessage(msg);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * DIYKeyAdapter2的子布局中有一个删除按键，为该按键设置点击事件
	 * 点击控件会获取按position所设的tag，因此可以取得该按键在集合中的position 通过position去删除该控件
	 */
	private OnClickListener deletel = new OnClickListener() {

		@Override
		public void onClick(View v) {

			switch (v.getId()) {
			case R.id.delete_img:
				int position = (Integer) v.getTag();
				mPairedKeys.remove(position);
				updateDIYKeyListView();
				break;

			default:
				break;
			}
		}
	};

	private OnClickListener testl = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.test_btn:
				int position = (Integer) v.getTag();
				String codeValue = mPairedKeys.get(position).getCodeValue();
				Log.i("wmy", "测试的码" + mPairedKeys.get(position).getName() + " " + mPairedKeys.size());
				String cmd = ConvertUtil.getInstance().convertInfraredCmd(codeValue);
				socket.sendMqttData(cmd);
				// 弹出对话框，询问用户是否观察到电器做出相应的响应，如有响应，则保存，如没有，则删除
				// showDeleteDialog(position);
				break;

			default:
				break;
			}
		}
	};

	private void updateDIYKeyListView() {
		mPairAdapter.notifyDataSetChanged();
		if (mPairedKeys.size() > 0) {
			mEnsureB.setText("DIY下一键");
		} else {
			mEnsureB.setText("开始DIY");
		}
	}

	class KeyPairExpandAdapter extends BaseExpandableListAdapter {
		private LayoutInflater inflater;
		private int imageResId;
		private int stringResId;
		private int bgDrawableResId;

		@Override
		public int getGroupCount() {
			// TODO Auto-generated method stub
			// Log.i("wmy", "更新按键列表 mKeyList.size() = " + mPairedKeys.size());
			return mPairedKeys.size();
		}

		public KeyPairExpandAdapter() {

		}

		public List<Key> getData() {
			return mPairedKeys;
		}

		@Override
		public int getChildrenCount(int groupPosition) {
			// TODO Auto-generated method stub
			// Log.i("wmy", "更新按键列表" +
			// mPairedKeys.get(groupPosition).getKeyNum() + " 按键有 "
			// + mPairedKeys.get(groupPosition).getCmds().size() + "个指令");
			return mPairedKeys.get(groupPosition).getCmds().size();
		}

		@Override
		public Object getGroup(int groupPosition) {
			// TODO Auto-generated method stub
			// Log.i("wmy", "getGroup" +
			// mPairedKeys.get(groupPosition).getKeyNum() + " 按键有 "
			// + mPairedKeys.get(groupPosition).getCmds().size() + "个指令");
			return mPairedKeys.get(groupPosition);
		}

		@Override
		public Object getChild(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getGroupId(int groupPosition) {
			// TODO Auto-generated method stub
			return groupPosition;
		}

		@Override
		public long getChildId(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return childPosition;
		}

		@Override
		public boolean hasStableIds() {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public View getGroupView(final int groupPosition, final boolean isExpanded, View view, ViewGroup parent) {
			// TODO Auto-generated method stub
			LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.item_pair_air_key, null);
			view.setTag(R.layout.item_layout, groupPosition);
			view.setTag(R.layout.item_main_device, -1);
			view.setTag(holdView);
			final Key k = mPairedKeys.get(groupPosition);
			final EditText nameEd = (EditText) view.findViewById(R.id.key_name_ed);
			ImageView keyImg = (ImageView) view.findViewById(R.id.key_img);
			TextView keyTv = (TextView) view.findViewById(R.id.key_tv);
			TextView test_tv = (TextView) view.findViewById(R.id.test_tv);
			ImageView deleteImg = (ImageView) view.findViewById(R.id.delete_img);
			TextView sign_size_tv1 = (TextView) view.findViewById(R.id.sign_size_tv1);
			TextView sign_size_tv = (TextView) view.findViewById(R.id.sign_size_tv);
			FrameLayout keyIconLayout = (FrameLayout) view.findViewById(R.id.key_icon_layout);
			LinearLayout key_info_layout = (LinearLayout) view.findViewById(R.id.key_info_layout);
			// if (k.getKeyNum() != 811 && k.getKeyNum() != 812 && k.getKeyNum()
			// != 832 && k.getKeyNum() != 833) {
			test_tv.setVisibility(View.VISIBLE);
			// }
			if (k.getKeyNum() == 800 || k.getKeyNum() == 4000) {
				keyIconLayout.setBackgroundResource(R.color.transparent);
			}
			// bgDrawableResId =
			// KeyManager.getInstance().getBackGroundResId(k.getKeyNum());
			// keyIconLayout.setBackgroundResource(bgDrawableResId);
			nameEd.setText(k.getName());
			if (k.getCmds().size() == 0 || k.getCmds() == null) {
				sign_size_tv.setText("1");
				sign_size_tv.setVisibility(View.GONE);
				sign_size_tv1.setVisibility(View.GONE);
				deleteImg.setVisibility(View.VISIBLE);
			} else {
				deleteImg.setVisibility(View.GONE);
				sign_size_tv.setVisibility(View.VISIBLE);
				sign_size_tv1.setVisibility(View.VISIBLE);
				sign_size_tv.setText(k.getCmds().size() + "");
			}
			if (k.getContentType() == 0) {
				imageResId = KeyManager.getInstance().getDrawableResId(k.getKeyNum());
				keyTv.setVisibility(View.GONE);
				keyImg.setImageResource(imageResId);
			} else {
				stringResId = KeyManager.getInstance().getStringResId(k.getKeyNum());
				keyImg.setVisibility(View.GONE);
				keyTv.setText(stringResId);
			}
			key_info_layout.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Log.i("wmy", "响应点击" + groupPosition);
					// mPairedKeyL.expandGroup(groupPosition);
					// Message message = Mess
					if (isExpanded) {
						mPairedKeyL.collapseGroup(groupPosition);
					} else {
						mPairedKeyL.expandGroup(groupPosition);
					}
				}
			});
			deleteImg.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					mPairedKeys.remove(groupPosition);
					notifyDataSetChanged();
				}
			});
			test_tv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					String testCmd = "";
					if (k.getKeyNum() != 811 && k.getKeyNum() != 812 && k.getKeyNum() != 832 && k.getKeyNum() != 833) {
						testCmd = ConvertUtil.getInstance()
								.convertInfraredCmd(mPairedKeys.get(groupPosition).getCodeValue());
						socket.sendMqttData(testCmd);
					} else if (k.getKeyNum() == 812) {
						if (tempPointer == 16) {
							String ir_data = mPairedKeys.get(groupPosition).getCmds().get(0).getCmd();
							testCmd = ConvertUtil.getInstance().convertInfraredCmd(ir_data);
							socket.sendMqttData(testCmd);
						} else {
							tempPointer--;
							List<KeyCmd> cmds = mPairedKeys.get(groupPosition).getCmds();
							boolean e = false;
							for (int i = 0; i < cmds.size(); i++) {
								if (tempPointer == cmds.get(i).getNum()) {
									testCmd = ConvertUtil.getInstance().convertInfraredCmd(cmds.get(i).getCmd());
									e = true;
									break;
								}
							}
							if (e) {
								socket.sendMqttData(testCmd);
							} else {
								if (tempPointer <= cmds.get(0).getNum()) {
									testCmd = ConvertUtil.getInstance().convertInfraredCmd(cmds.get(0).getCmd());
									socket.sendMqttData(testCmd);
								}
							}
						}
					} else if (k.getKeyNum() == 811) {
						if (tempPointer == 31) {
							String ir_data = mPairedKeys.get(groupPosition).getCmds()
									.get(mPairedKeys.get(groupPosition).getCmds().size() - 1).getCmd();
							testCmd = ConvertUtil.getInstance().convertInfraredCmd(ir_data);
							socket.sendMqttData(testCmd);
						} else {
							tempPointer++;
							List<KeyCmd> cmds = mPairedKeys.get(groupPosition).getCmds();
							boolean e = false;
							for (int i = 0; i < cmds.size(); i++) {
								if (tempPointer == cmds.get(i).getNum()) {
									testCmd = ConvertUtil.getInstance().convertInfraredCmd(cmds.get(i).getCmd());
									e = true;
									break;
								}
							}
							if (e) {
								socket.sendMqttData(testCmd);
							} else {
								if (tempPointer >= cmds.get(cmds.size() - 1).getNum()) {
									testCmd = ConvertUtil.getInstance()
											.convertInfraredCmd(cmds.get(cmds.size() - 1).getCmd());
									socket.sendMqttData(testCmd);
								}
							}
						}
					} else if (k.getKeyNum() == 832) {
						// 832 是模式
						// 循环模式是 1，2，3，4，5
						int size = k.getCmds().size();
						if (modelPointer == 5) {
							modelPointer = 1;
						} else {
							modelPointer++;
						}
						for (int i = 0; i < size; i++) {
							if (modelPointer == k.getCmds().get(i).getNum()) {
								String testModelCmd = ConvertUtil.getInstance()
										.convertInfraredCmd(k.getCmds().get(i).getCmd());
								socket.sendMqttData(testModelCmd);
								break;
							}
						}
					} else if (k.getKeyNum() == 833) {
						// 833 是风量
						// 循环模式是 1，2，3，4，5
						int size = k.getCmds().size();
						if (windPointer == 5) {
							windPointer = 1;
						} else {
							windPointer++;
						}
						for (int i = 0; i < size; i++) {
							if (windPointer == k.getCmds().get(i).getNum()) {
								String testModelCmd = ConvertUtil.getInstance()
										.convertInfraredCmd(k.getCmds().get(i).getCmd());
								socket.sendMqttData(testModelCmd);
								break;
							}
						}
					}

					// socket.sendMqttData(testCmd);
				}
			});
			nameEd.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					nameEd.requestFocus();
				}
			});
			nameEd.addTextChangedListener(new TextWatcher() {

				@Override
				public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

				}

				@Override
				public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

				}

				@Override
				public void afterTextChanged(Editable arg0) {
					nameEd.setTextColor(getResources().getColor(R.color.gray_introdution));
					mPairedKeys.get(groupPosition).setName(arg0.toString());
				}
			});
			return view;
		}

		@Override
		public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View view,
				ViewGroup parent) {
			// TODO Auto-generated method stub
			LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.item_pair_air_key_cmd, null);
			childHoldView = new ChildHoldView();
			childHoldView.testBtn = (TextView) view.findViewById(R.id.test_btn);
			childHoldView.deleteImg = (ImageView) view.findViewById(R.id.delete_img);
			childHoldView.sign_length = (TextView) view.findViewById(R.id.sign_lengh_tv);
			childHoldView.sign_name = (TextView) view.findViewById(R.id.sign_tv);
			view.setTag(R.layout.item_layout, groupPosition);
			view.setTag(R.layout.item_main_device, childPosition);
			view.setTag(childHoldView);
			KeyCmd kc = mPairedKeys.get(groupPosition).getCmds().get(childPosition);
			if (kc.getType() == 1) { // 模式
				switch (kc.getNum()) { // 1送风 2制冷 3取暖 4抽湿 5自动
				case 1:
					childHoldView.sign_name.setText("送风");
					break;
				case 2:
					childHoldView.sign_name.setText("制冷");
					break;
				case 3:
					childHoldView.sign_name.setText("取暖");
					break;
				case 4:
					childHoldView.sign_name.setText("抽湿");
					break;
				case 5:
					childHoldView.sign_name.setText("自动");
					break;
				default:
					break;
				}
			} else if (kc.getType() == 2) {// 风量
				switch (kc.getNum()) { // 1一档 2二档 3三档 4四档 5自动
				case 1:
					childHoldView.sign_name.setText("一档");
					break;
				case 2:
					childHoldView.sign_name.setText("二档");
					break;
				case 3:
					childHoldView.sign_name.setText("三档");
					break;
				case 4:
					childHoldView.sign_name.setText("四档");
					break;
				case 5:
					childHoldView.sign_name.setText("自动");
					break;
				default:
					break;
				}
			} else if (kc.getType() == 4) {// 温度
				switch (kc.getNum()) { // 1一档 2二档 3三档 4四档 5自动
				case 16:
					childHoldView.sign_name.setText("16度");
					break;
				case 17:
					childHoldView.sign_name.setText("17度");
					break;
				case 18:
					childHoldView.sign_name.setText("18度");
					break;
				case 19:
					childHoldView.sign_name.setText("19度");
					break;
				case 20:
					childHoldView.sign_name.setText("20度");
					break;
				case 21:
					childHoldView.sign_name.setText("21度");
					break;
				case 22:
					childHoldView.sign_name.setText("22度");
					break;
				case 23:
					childHoldView.sign_name.setText("23度");
					break;
				case 24:
					childHoldView.sign_name.setText("24度");
					break;
				case 25:
					childHoldView.sign_name.setText("25度");
					break;
				case 26:
					childHoldView.sign_name.setText("26度");
					break;
				case 27:
					childHoldView.sign_name.setText("27度");
					break;
				case 28:
					childHoldView.sign_name.setText("28度");
					break;
				case 29:
					childHoldView.sign_name.setText("29度");
					break;
				case 30:
					childHoldView.sign_name.setText("30度");
					break;
				case 31:
					childHoldView.sign_name.setText("31度");
					break;
				default:
					break;
				}
			}
			childHoldView.testBtn.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					String testCmd = ConvertUtil.getInstance()
							.convertInfraredCmd(mPairedKeys.get(groupPosition).getCmds().get(childPosition).getCmd());
					socket.sendMqttData(testCmd);

				}
			});
			childHoldView.deleteImg.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Message msg = Message.obtain();
					msg.what = 3;
					msg.arg1 = groupPosition;
					msg.arg2 = childPosition;
					mHandler.sendMessage(msg);
				}
			});
			return view;
		}

		@Override
		public boolean isChildSelectable(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return true;
		}

		HoldView holdView;
		ChildHoldView childHoldView;

		class HoldView {
			ImageView typeImg;
			TextView typeName;
			ImageView biao;
		}

		class ChildHoldView {
			TextView testBtn;
			ImageView deleteImg;
			TextView sign_length, sign_name;
		}

	}

}